<?php
 /***************************************************************
 * Mor-MVC Framework, A framework that can easily let you build a powerful
 * and scalable web application based on PHP language,
 * this framewrok is a copy of the Zend Behavior Framework
 *  Copyright (C) 2010  Nabil Droussi <nabildroussi@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************/
class HttpRequest
{
	public function isPost()
	{
		if($_SERVER["REQUEST_METHOD"] == "POST")
			return true;
		return false;
	}
	public function isGet()
	{
		if($_SERVER["REQUEST_METHOD"] == "GET")
			return true;
		return false;
	}
	public function getParam($key)
	{
		if(!is_string($key))
			return false;
		
		if(!isset($_GET[$key]))
			return false;
		
		return stripslashes($_GET[$key]);
	}
	public function getPost($key)
	{
		if(!is_string($key))
			return false;
		
		if(!isset($_POST[$key]))
			return false;
		
		return stripslashes($_POST[$key]);
	}
	public function getUrl()
	{
		$url = "http".(($_SERVER["SERVER_PORT"]==443)?"s":"")."://".$_SERVER["HTTP_HOST"].dirname($_SERVER["PHP_SELF"]);
		return $url;
	}
	public function redirect($url)
	{
		if(headers_sent())
			throw new Exception("cannot redirect because the header is already sent.");
		
		header("Location:".$url);
	}
	public function addHeader($key,$value = null)
	{
		if(headers_sent())
			throw new Exception("cannot add header because the header is already sent.");
		
		if(isset($value))
			header("{$key}:{$value}");
		else
			header("{$key}");
	}
}
?>